{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    ""
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# 1、 模型调用的分类\n",
    "\n",
    "角度1：按照模型功能的不同\n",
    "\n",
    "非对话模型：（LLMs、Text Model）\n",
    "\n",
    "对话模型：（Chat Models）  (推荐)\n",
    "\n",
    "嵌入模型：（Embedding Models） (放到最后RAG章节讲解)\n",
    "\n",
    "\n",
    "角度2：按照模型调用时，参数书写的位置的不同（api-key、base_url、model-name）\n",
    "\n",
    "硬编码的方式：将参数书写在代码中\n",
    "\n",
    "使用环境变量的方式\n",
    "\n",
    "使用配置文件的方式 (推荐)\n",
    "\n",
    "角度3：具体API的调用\n",
    "\n",
    "使用LangChain提供的API (推荐)\n",
    "\n",
    "使用OpenAI 官方的API\n",
    "\n",
    "使用其它平台提供的API\n",
    "\n",
    "\n",
    "# 2、角度1：非对话模型的调用\n"
   ],
   "id": "12bf235f6d02f0d6"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T10:14:06.350612Z",
     "start_time": "2025-08-22T10:14:03.105084Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import dotenv\n",
    "from langchain_openai import OpenAI\n",
    "dotenv.load_dotenv()\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY1\")\n",
    "os.environ[\"OPENAI_BASE_URL\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "\n",
    "\n",
    "###########核心代码############\n",
    "llm = OpenAI()\n",
    "str = llm.invoke(\"写一首关于春天的诗\")  # 直接输入字符串\n",
    "print(str)\n",
    "print(type(str))"
   ],
   "id": "6bc1c5da87577157",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "春来花开满山川，\n",
      "万物复苏展新颜。\n",
      "草儿抬头向阳笑，\n",
      "树木抽枝拥绿帘。\n",
      "\n",
      "雨过天晴春意浓，\n",
      "蝴蝶飞舞乐悠然。\n",
      "小鸟歌声悦耳听，\n",
      "春风吹拂暖人心。\n",
      "\n",
      "田野耕作忙碌处，\n",
      "村庄喜气洋溢间。\n",
      "农人欢聚乐园地，\n",
      "共享春天的丰收年。\n",
      "\n",
      "春雨润泽滋养土，\n",
      "春风吹拂滋养花。\n",
      "生机勃发处处见，\n",
      "春天真是美妙的奇迹。\n",
      "\n",
      "让我们迎接春天的到来，\n",
      "放飞心灵把欢乐挥洒。\n",
      "让春天的歌谣响彻天地，\n",
      "\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 2、角度1：对话模型的调用",
   "id": "eb3640984fb46ec3"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T10:17:12.497957Z",
     "start_time": "2025-08-22T10:17:11.206815Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import SystemMessage, HumanMessage\n",
    "import os\n",
    "import dotenv\n",
    "dotenv.load_dotenv()\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY1\")\n",
    "os.environ[\"OPENAI_BASE_URL\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "\n",
    "\n",
    "########核心代码############\n",
    "chat_model = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "messages = [\n",
    "    SystemMessage(content=\"我是人工智能助手，我叫小智\"),\n",
    "    HumanMessage(content=\"你好，我是小明，很高兴认识你\")\n",
    "]\n",
    "\n",
    "#输入：list[basemessage]\n",
    "#输出：AIMessage\n",
    "response = chat_model.invoke(messages)  # 输入消息列表\n",
    "\n",
    "print(type(response))  # <class 'langchain_core.messages.ai.AIMessage'>\n",
    "print(response.content)"
   ],
   "id": "e0499aa3e9f8c831",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'langchain_core.messages.ai.AIMessage'>\n",
      "你好，小明！很高兴认识你。有任何想聊的话题或者问题吗？\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 2、角度1：嵌入模型的调用",
   "id": "d18bab70e5b578e8"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T10:18:43.426518Z",
     "start_time": "2025-08-22T10:18:42.441648Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import dotenv\n",
    "from langchain_openai import OpenAIEmbeddings\n",
    "dotenv.load_dotenv()\n",
    "os.environ['OPENAI_API_KEY'] = os.getenv(\"OPENAI_API_KEY1\")\n",
    "os.environ['OPENAI_BASE_URL'] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "\n",
    "\n",
    "#############\n",
    "embeddings_model = OpenAIEmbeddings(\n",
    "    model=\"text-embedding-ada-002\"\n",
    ")\n",
    "\n",
    "res1 = embeddings_model.embed_query('我是文档中的数据')\n",
    "print(res1)\n",
    "# 打印结果：[-0.004306625574827194, 0.003083756659179926, -0.013916781172156334, ...., ]"
   ],
   "id": "f5d25adfdd0966a8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-0.032839685678482056, 0.002757745562121272, -0.010489282198250294, -0.021119264885783195, -0.016841946169734, 0.02123182639479637, -0.03033520095050335, 0.0030461831483989954, -0.01864292286336422, -0.024594588205218315, 0.008948602713644505, 0.031038707122206688, -0.007893343456089497, 0.008610920049250126, -0.004913993179798126, 0.01269829273223877, 0.010165669023990631, -0.003032113192602992, 0.009342566132545471, -0.01716555841267109, -0.0017429373692721128, 0.010341545566916466, -0.0001418005267623812, -0.0003348251339048147, -0.01663089357316494, 0.01847408153116703, 0.013676166534423828, -0.022413717582821846, -0.001504624611698091, -0.01528016198426485, 0.02521367371082306, -0.0197403933852911, -0.020415758714079857, -0.018009766936302185, -0.0012698292266577482, -0.007991833612322807, -0.009645074605941772, -0.022990593686699867, 0.014815847389400005, -0.007717466447502375, 0.009652109816670418, 0.013113361783325672, -0.0027858857065439224, 0.018009766936302185, 0.0053220270201563835, 0.005547149106860161, 0.016898225992918015, -0.021541370078921318, -0.0028878941666334867, 0.015237951651215553, 0.0031974371522665024, 0.020078076049685478, -0.024946341291069984, -0.023497117683291435, 0.010060143657028675, 0.0029564860742539167, 0.008343587629497051, 0.026100091636180878, -0.022638840600848198, -0.018150467425584793, 0.0055858418345451355, 0.01663089357316494, -0.04316715896129608, 0.00393611891195178, -0.01389425341039896, 0.0011599063873291016, -0.006176787428557873, 0.0029002055525779724, 0.029125170782208443, 0.011453086510300636, 0.010644054040312767, 0.023539328947663307, 0.0006489847437478602, 0.015955528244376183, 0.05006152391433716, -0.006711452268064022, -0.008990813046693802, -0.0034172828309237957, 0.011713383719325066, -0.021245896816253662, 0.01789720542728901, -0.026029741391539574, -0.0022793610114604235, -0.0036547163035720587, 0.021668000146746635, 0.024566447362303734, 0.007520484738051891, 0.05222832411527634, -0.02887190692126751, -0.03286782279610634, 0.007154661230742931, 0.015350512228906155, 0.005068764556199312, 0.014407813549041748, 0.008660165593028069, 0.033543191850185394, 0.00439339829608798, 0.01879769377410412, 0.004544652067124844, -0.040690816938877106, 0.008069219999015331, -0.013929429464042187, -0.040296852588653564, -0.0034067302476614714, -0.030841724947094917, 0.01161489263176918, 0.01865699328482151, -0.008259166963398457, 0.020556461066007614, -0.0034612519666552544, -0.02251220867037773, 0.018558502197265625, 0.03241758048534393, -0.026620686054229736, -0.019881093874573708, -0.010383755899965763, 0.009455127641558647, -0.013218887150287628, -0.029716115444898605, -0.005318509414792061, 0.001127369236201048, 0.037933070212602615, 0.010665158741176128, -0.024721218273043633, 0.01664496399462223, 0.03033520095050335, 0.00858981441706419, -0.02704279124736786, 0.018952464684844017, 0.006546128075569868, 0.018516290932893753, 0.016138439998030663, 0.02269512042403221, 0.009940546937286854, -0.03981846943497658, 0.029941236600279808, -0.019599691033363342, 0.0180660467594862, -0.017461031675338745, -0.011291279457509518, 0.016898225992918015, 0.025551356375217438, -0.010369686409831047, -0.01879769377410412, 0.0010877969907596707, -0.00626472570002079, 0.0030760823283344507, -0.014632935635745525, 0.00016972095181699842, -0.0149002680554986, 0.026803597807884216, -0.008983777835965157, 0.0007870479021221399, 0.02470714971423149, -0.00794962327927351, -0.003974811639636755, -0.01571633480489254, 0.0016119093634188175, 0.008463183417916298, -0.017264049500226974, -0.0036125059705227613, 0.023440837860107422, 0.021330317482352257, -0.00924407597631216, 0.013190747238695621, 0.035372309386730194, -0.01795348711311817, -0.012466135434806347, -0.009328496642410755, 0.0025871451944112778, -0.01663089357316494, 0.01919165812432766, -0.00016576371854171157, -0.0026399081107228994, -0.010925455950200558, 0.028801556676626205, 0.00200851121917367, 9.019173739943653e-05, -0.009314426220953465, -0.008308411575853825, -0.032445721328258514, -0.0014114099321886897, 0.0034630107693374157, -0.005051176995038986, -0.010362651199102402, -0.0022529796697199345, 0.005916489753872156, -0.019473060965538025, -0.008899357169866562, -0.010482246987521648, 0.022934312000870705, 0.01452037412673235, -0.002182628959417343, -0.015237951651215553, -0.6186354756355286, -0.01934642903506756, -0.020528320223093033, -0.004330082796514034, 0.016208790242671967, 0.008660165593028069, 0.005884832236915827, 0.023665959015488625, -0.017798714339733124, -0.04828868806362152, -0.007189836818724871, -0.0015846483875066042, 0.0016646722797304392, 0.011424945667386055, -0.007886308245360851, -0.024946341291069984, 0.0031024636700749397, 0.016884155571460724, -0.01777057535946369, 0.005955182481557131, -0.003012766595929861, 0.022273017093539238, -0.019430849701166153, 0.019810743629932404, 0.014661075547337532, 0.016729384660720825, -0.0031200514640659094, -0.009680249728262424, -0.0005254314164631069, 0.019233867526054382, -0.025874970480799675, 0.004157723393291235, 0.00886418204754591, 0.005406447686254978, 0.04204155132174492, -2.7714309908333234e-05, 0.004636107943952084, 0.01453444454818964, 0.01830524019896984, 0.013859078288078308, -0.003834110451862216, -0.011410876177251339, -0.0006419497076421976, 0.0038130052853375673, 0.005839104298502207, 0.0025730750057846308, 0.030757304280996323, 0.015322372317314148, 0.03177035599946976, 0.024355394765734673, -0.01847408153116703, -0.024172484874725342, -0.004386363085359335, -0.004899922758340836, 0.015167600475251675, 0.004593897610902786, 0.007590835448354483, -0.056618206202983856, 0.026733247563242912, -0.002351470524445176, 0.0118892602622509, 0.012817888520658016, -0.01847408153116703, -0.004727563820779324, -0.013169641606509686, -0.0033821074757725, -0.028759347274899483, 0.007028030231595039, 0.006834565661847591, -0.010658123530447483, 0.017081137746572495, 0.0017271084943786263, 0.007281292695552111, 0.015153530053794384, 0.021864982321858406, 0.025368444621562958, 0.025846829637885094, -0.019107237458229065, -0.010165669023990631, 0.0008134294184856117, 0.0006947126821614802, -0.0018009766936302185, -0.008259166963398457, -0.02048610895872116, -0.011861120350658894, -0.011319420300424099, -0.030757304280996323, -0.0246930792927742, 3.0063911253819242e-05, -0.006795872934162617, 0.015012829564511776, 0.016743455082178116, 0.013211852870881557, -0.005772271193563938, -0.005645639728754759, 0.007675256114453077, -0.014421883970499039, -0.023468976840376854, -0.004615002777427435, 0.010890280827879906, -0.004826054908335209, -0.0006982302293181419, 0.016208790242671967, 0.005241123493760824, 0.02868899516761303, 0.0026188029441982508, -0.0177565049380064, -0.003918531350791454, 0.01588517799973488, -0.0013349036453291774, 0.0014034955529496074, 0.0029705562628805637, -0.003200954757630825, -0.0051004220731556416, -0.02852015383541584, -0.022568488493561745, 0.02360967919230461, 0.00465369550511241, -0.0049386159516870975, 0.010390791110694408, 0.014942478388547897, 0.017686154693365097, 0.025874970480799675, -0.01629321090877056, 0.01198071613907814, 0.021696140989661217, -0.0027595043648034334, -0.006321005988866091, -0.0008081531268544495, -0.022441858425736427, -0.0059762876480817795, -0.03677932173013687, 0.029012609273195267, -0.024003641679883003, 0.018713273108005524, -0.017601732164621353, 0.019782602787017822, 0.002040168968960643, 0.00822399090975523, -0.005332579370588064, -0.030644744634628296, 0.0006709693698212504, -0.002543176058679819, -0.033909015357494354, 0.0004372732655610889, -0.019641902297735214, -0.005825033877044916, -0.010320440866053104, -0.00457631004974246, 0.001098349574021995, -0.016377631574869156, 0.0052481587044894695, -0.00866719987243414, 0.006542610470205545, 0.012198803015053272, 0.018389660865068436, -0.0016769836656749249, -0.009201865643262863, -0.019318288192152977, -0.0034313530195504427, -0.024608658626675606, 0.0019364017061889172, -0.004738116171211004, -0.0032695464324206114, -0.02501669153571129, -0.03469694033265114, -0.019796673208475113, 0.0114319808781147, -0.04074709862470627, -0.022892102599143982, 0.00032075500348582864, 0.01260683685541153, -0.010524457320570946, -0.021119264885783195, 0.003974811639636755, -0.004488371778279543, -0.017489172518253326, 0.0055225263349711895, 0.01733439974486828, -0.0269020888954401, -0.002099966863170266, -0.005023036617785692, 0.000836733088362962, -0.01753138191998005, 0.028435733169317245, 0.01525202114135027, -0.000585229485295713, 0.006412461865693331, -0.014632935635745525, 0.007590835448354483, 0.003533361479640007, 0.00046299523091875017, -0.026972439140081406, 0.011277209036052227, 0.01792534627020359, 0.01861478202044964, -0.0024464440066367388, 0.02175242081284523, 0.014984688721597195, 0.013753551989793777, 0.008751621469855309, 0.022005684673786163, -0.017249979078769684, -0.017629873007535934, 0.024594588205218315, -0.043251581490039825, -0.008997848257422447, -0.011593786999583244, 0.0062049273401498795, -0.00019291468197479844, 0.024749359115958214, -0.00019797113782260567, -0.017658013850450516, -0.006532058119773865, 0.02652219496667385, 0.022976523265242577, -0.015040969476103783, -0.007379783317446709, -0.0035667780321091413, 0.00342783541418612, -0.009054129011929035, -0.010383755899965763, 0.011199823580682278, -0.002666289685294032, -0.01848815195262432, 0.010271195322275162, 0.016039948910474777, 0.04026871174573898, 0.02324385568499565, -0.0027313639875501394, -0.026240793988108635, -0.014928407967090607, -0.0008978502009995282, 0.002045445144176483, 0.0030760823283344507, -0.0028966881800442934, 0.031151268631219864, -0.021499158814549446, 0.024946341291069984, 6.688808207400143e-05, -0.010257124900817871, 0.013486219570040703, 0.0018115292768925428, -0.022990593686699867, 0.002675083465874195, -0.0016435671132057905, 0.01416862104088068, 0.009827986359596252, -0.02503076195716858, 0.020373549312353134, -0.01588517799973488, 0.011931470595300198, -0.01306411623954773, -0.014661075547337532, 0.014006814919412136, -0.02337048575282097, 0.007471239194273949, 0.014689216390252113, 0.016912296414375305, 0.02815433032810688, 0.012768642976880074, -0.0012601560447365046, -0.0013269891496747732, 0.01528016198426485, 0.007830027490854263, -0.01972632296383381, -0.021161476150155067, -0.025171462446451187, -0.029547274112701416, 0.012480205856263638, 0.025832759216427803, -0.01543493289500475, 0.01795348711311817, -0.005153185222297907, 0.0246930792927742, -0.007597870193421841, 0.030447762459516525, -0.01187518984079361, 0.01737661100924015, -0.005107457283884287, -0.03351505100727081, -0.0061591994017362595, -0.01233246922492981, 0.033543191850185394, 0.004062749911099672, -0.017686154693365097, -0.01917758770287037, 0.038467735052108765, -0.019458990544080734, 0.0011168166529387236, 0.007309432607144117, -0.004632590338587761, 0.01123499870300293, -0.02030319720506668, 0.0032431650906801224, 0.027858858928084373, 0.02835131250321865, -0.0010710887145251036, -0.0387209989130497, 0.02176649123430252, -0.008139570243656635, -0.016715314239263535, -0.0094903027638793, -0.03452809900045395, 0.03362761065363884, -0.0022019753232598305, 0.0026135267689824104, 0.01646205224096775, -0.01198071613907814, -0.014956548810005188, 0.0004429892578627914, -0.0007369230734184384, -0.029181450605392456, -0.010777720250189304, -0.03649791702628136, 0.007443098817020655, -0.007822992280125618, 0.004206968937069178, 0.027380473911762238, -0.005628052167594433, 0.007112450897693634, -0.01214955747127533, -0.034105997532606125, 0.016841946169734, -0.0013146777637302876, 0.03416227549314499, -0.0004425495571922511, -0.02652219496667385, 0.006440602242946625, 0.0023215715773403645, -0.02854829467833042, -0.02760559506714344, 0.0015301266685128212, -0.0035228088963776827, 0.0036441637203097343, -0.009968687780201435, 0.01306411623954773, 0.007154661230742931, 0.021330317482352257, 0.003834110451862216, -0.014562585391104221, -0.021358458325266838, -0.010468176566064358, -0.024622729048132896, -0.010742544196546078, -0.004509476944804192, 0.02397550269961357, 0.009018953889608383, -0.006384321488440037, -0.016687175258994102, 0.023637818172574043, 0.009891301393508911, 0.009272215887904167, -0.00015982789045665413, -0.00866719987243414, 0.023651888594031334, 0.0003348251339048147, 0.007429028861224651, -0.00393611891195178, 0.009898336604237556, -0.00763304578140378, -0.00351929129101336, 0.00822399090975523, 0.03222059831023216, 0.01792534627020359, 0.01698264665901661, 0.00649336539208889, -0.031939197331666946, -0.0017209528014063835, -0.004854194819927216, -0.012888239696621895, 0.015561563894152641, -0.004706458654254675, -0.022723261266946793, -0.0009444574825465679, 0.0002915155200753361, -0.024172484874725342, -0.025635777041316032, 0.029125170782208443, 0.011002842336893082, 0.018966535106301308, -0.012001820839941502, 0.0016268588369712234, -0.0019152965396642685, -0.006257690489292145, 0.005353684537112713, -0.0014492233749479055, -0.014759566634893417, -0.019824814051389694, -0.008716445416212082, -0.016391701996326447, -0.019318288192152977, -0.012867134064435959, 0.022934312000870705, -0.0022529796697199345, -0.007970728911459446, -0.01187518984079361, -0.023722240701317787, 0.003647681325674057, -0.004337117541581392, 0.02467900887131691, 0.004776809364557266, 0.0027788507286459208, 0.0221041738986969, 0.003661751514300704, -0.019121307879686356, -0.0013815108686685562, -0.011424945667386055, -0.03452809900045395, 0.011924435384571552, -0.02396143227815628, -0.010482246987521648, 0.00340497144497931, 0.004738116171211004, -0.009708389639854431, 0.004178828559815884, 0.02542472630739212, 0.0031077400781214237, 0.009068199433386326, -0.006546128075569868, -0.003742654575034976, 0.008913427591323853, -0.009082268923521042, -0.01629321090877056, 0.004657213110476732, -0.026029741391539574, -0.02722570300102234, -0.0010939526837319136, 0.01698264665901661, 0.006612961180508137, 0.005343132186681032, 0.023103153333067894, 0.004776809364557266, -0.004192898981273174, 0.017503242939710617, -0.007137073669582605, 0.016405772417783737, -0.008660165593028069, 0.018868044018745422, 0.014815847389400005, -0.00976467039436102, 0.04330785945057869, -0.013021905906498432, -0.0123465396463871, 0.004214004147797823, 0.0029617624823004007, 0.025143323466181755, 0.04277319461107254, -0.0025097595062106848, 0.016152510419487953, -0.01454851496964693, 0.0008974105003289878, -0.01831931062042713, -0.009849091060459614, 0.01754545234143734, 0.015336441807448864, -0.0012847788166254759, 0.009891301393508911, -0.01957155205309391, -0.005318509414792061, 0.01352139562368393, 0.003946671728044748, -0.015519353561103344, 0.0055225263349711895, -0.018572572618722916, -0.010390791110694408, 0.0009963411139324307, 0.014773637056350708, 0.028252821415662766, -0.022723261266946793, -0.010461142286658287, 0.003341655945405364, -0.014210831373929977, 0.041056640446186066, 0.010397826321423054, 0.012374679557979107, 0.005979805253446102, -0.012649047188460827, 0.004059232771396637, -0.02413027361035347, -0.006852153688669205, 0.012170663103461266, 0.01829116977751255, 0.0005786340916529298, 0.03514718636870384, -0.006454672198742628, 0.01169227808713913, 0.01661682315170765, 0.0014228419167920947, 0.012409854680299759, -0.010017932392656803, -0.0038200404960662127, -0.021907193586230278, 0.0037004442419856787, 0.008216955699026585, 0.016349490731954575, 0.020697161555290222, 0.007970728911459446, 0.008195850998163223, 0.0059129721485078335, 0.022273017093539238, 0.018333379179239273, -0.0014342739013954997, -0.04986454173922539, -0.008343587629497051, 0.0026100091636180878, 0.004541134461760521, 0.004878817591816187, -0.023257926106452942, -0.006816978100687265, 0.03343062847852707, -0.033346209675073624, 0.033683892339468, -0.0016769836656749249, 0.01625099964439869, -0.03146081045269966, -0.006795872934162617, -0.027028720825910568, 0.023694099858403206, -0.02870306558907032, 0.010531492531299591, -0.011129473336040974, 0.0018255994655191898, 0.04209782928228378, 0.0026416669134050608, 0.026606615632772446, 0.012015891261398792, -0.008688305504620075, 0.011199823580682278, 0.01793941669166088, 0.0049562035128474236, -0.01995144411921501, -0.011220929212868214, -0.0025238296948373318, -0.027464894577860832, -0.020514249801635742, -0.023539328947663307, -0.03731398656964302, 0.02541065588593483, 0.001996199833229184, 0.0020067524164915085, 0.016602754592895508, -0.007288327440619469, -0.01271236315369606, 0.007123003713786602, 0.010010898113250732, 0.031939197331666946, 0.0021210722625255585, 0.03604767471551895, 0.034809503704309464, -0.0050546941347420216, -0.030391480773687363, -0.062246255576610565, -0.0029388985130935907, -0.01571633480489254, 0.02868899516761303, 0.034837644547224045, -0.026789527386426926, -0.013570641167461872, 0.01024305447936058, 0.009919442236423492, 0.017306260764598846, -0.015055039897561073, 0.0051742903888225555, 0.01242392510175705, -0.021541370078921318, -0.0024587553925812244, -0.010454107075929642, -0.03106684796512127, 0.012381714768707752, -0.007274257484823465, -0.015477143228054047, -0.021513229236006737, -0.024228764697909355, 0.015575634315609932, 0.007414958905428648, -0.031010568141937256, 0.02999751828610897, -0.009279251098632812, -0.015561563894152641, 9.733672050060704e-05, -0.0123465396463871, -0.020753441378474236, 0.01453444454818964, -0.01187518984079361, 0.012360609136521816, -0.0002117114927386865, -0.022399647161364555, 0.010060143657028675, 0.017798714339733124, -0.02391922101378441, 0.002272326033562422, -0.030053798109292984, 0.049611277878284454, -0.02303280308842659, -0.0009972205152735114, -0.0033082393929362297, -0.011347560212016106, 0.006475777365267277, 0.0206549521535635, -0.016743455082178116, -0.011263139545917511, -0.007794852368533611, -0.012022926472127438, -0.021808702498674393, 0.009004883468151093, 0.016152510419487953, -0.0026381495408713818, -0.023511188104748726, -0.014379673637449741, -0.008097359910607338, -0.001006893697194755, -0.0008653129916638136, -0.006190857384353876, -0.01902281679213047, 0.0005219138693064451, 0.01152343675494194, 0.019473060965538025, -0.022582558915019035, -0.004203451331704855, 0.02360967919230461, 0.030813585966825485, 0.0050546941347420216, 0.026733247563242912, 0.007126520853489637, -0.012226942926645279, -0.021077055484056473, 0.010172704234719276, 0.022624770179390907, -0.02064088173210621, 0.03238943964242935, -0.009370706975460052, -0.025551356375217438, -0.01883990503847599, -0.003918531350791454, 0.020007725805044174, -0.017264049500226974, 0.01051038783043623, 0.03717328608036041, 0.004826054908335209, 0.003918531350791454, -0.01525202114135027, -0.007193353958427906, 0.014246007427573204, -0.019993655383586884, 0.014112341217696667, -0.010454107075929642, -0.0257624089717865, 0.010390791110694408, -0.008399867452681065, -0.0024956893175840378, 0.006282313261181116, -0.044180210679769516, -0.025537285953760147, -0.0029336221050471067, 0.020556461066007614, -0.0021105194464325905, -0.017418822273612022, -0.012388749979436398, -0.004337117541581392, -0.0008767449762672186, 0.015167600475251675, 0.015322372317314148, 0.01679973490536213, 0.01665903441607952, -0.0001921452203532681, 0.012860098853707314, 0.00958175864070654, -0.007351642940193415, 0.00021764733537565917, -0.006289348471909761, -0.021682070568203926, -0.030278921127319336, -0.0026275969576090574, -0.020359478890895844, -0.007534554693847895, 0.015167600475251675, -0.012571661733090878, -0.03874913975596428, -0.0019416779978200793, -0.014801776967942715, -0.02685987949371338, -0.018037907779216766, 0.020246917381882668, 0.0054767983965575695, 0.016011808067560196, -0.006982302293181419, 0.022441858425736427, -0.0027823683340102434, 0.014049025252461433, -0.02940657176077366, -0.013422904536128044, 0.010271195322275162, -0.022976523265242577, 0.007801887113600969, 0.011410876177251339, -0.016208790242671967, -0.010411896742880344, 0.006943609565496445, -0.012325434014201164, 0.011009876616299152, 0.0180660467594862, 0.008702375926077366, -0.013591745868325233, -0.029209591448307037, 0.00794258899986744, -0.0015573875280097127, -0.01453444454818964, 0.0022019753232598305, -0.03241758048534393, -0.005874279420822859, -0.004695905838161707, 0.005751165561378002, -0.0055225263349711895, 0.007087828125804663, 0.007407923694700003, -0.00411903066560626, -0.0008758656331337988, -0.006064226385205984, 0.01993737556040287, -0.0017033651238307357, -0.008378762751817703, 0.0032660290598869324, -0.01716555841267109, -0.009954617358744144, 0.056252382695674896, 0.007837062701582909, -0.00011129693302791566, -0.003090152284130454, 0.014506304636597633, -0.028309103101491928, 0.004280837252736092, 0.008252131752669811, 0.002071826718747616, 0.02120368555188179, -0.008076255209743977, 0.024059923365712166, -0.007879273034632206, 0.018741413950920105, 0.010897316038608551, -0.012599801644682884, -0.0290407482534647, 0.001027119462378323, 0.007337572984397411, -0.022357437759637833, -0.015406792983412743, -0.013324413448572159, -0.012909344397485256, -0.012142522260546684, -0.00203665136359632, -0.01920572854578495, -0.019107237458229065, -0.01826302893459797, 0.020570531487464905, -0.0024956893175840378, -0.01643391139805317, -0.002263532252982259, 0.020190637558698654, 0.028759347274899483, 0.002894929377362132, 0.3115689754486084, -0.012592766433954239, 0.007618975825607777, 0.017081137746572495, 0.016701243817806244, 0.036103952676057816, 0.007808922324329615, -0.004354705568403006, -0.0033117569983005524, 0.019079096615314484, 0.00895563792437315, -0.0017438167706131935, 0.0094903027638793, -0.0007874876027926803, -0.0049562035128474236, -0.02431318536400795, -0.03525974601507187, -0.005223535932600498, -0.022540349513292313, -0.023525258526206017, 0.034837644547224045, -0.01361988577991724, 0.009602864272892475, -0.02725384198129177, 0.015491213649511337, -0.012543520890176296, -0.012318398803472519, -0.010665158741176128, 0.017643943428993225, 0.02045796997845173, 0.0004660730774048716, -0.006539092864841223, 0.0006775647052563727, -0.012874169275164604, -0.024397606030106544, 0.008962673135101795, 0.022821752354502678, -0.005399412475526333, 0.03222059831023216, 6.0127822507638484e-05, -0.005673780106008053, -0.03644163906574249, -0.0034893923439085484, 0.00022798008285462856, -0.006092366296797991, 0.03905868157744408, -0.013957569375634193, -0.019881093874573708, -0.009201865643262863, 0.025663917884230614, -0.01952934078872204, -0.008751621469855309, 0.017629873007535934, 0.016602754592895508, -0.024622729048132896, 0.015477143228054047, 0.0128038190305233, 0.006641101557761431, -0.018755484372377396, -0.0036089883651584387, 0.004389880690723658, 0.012564626522362232, 0.01470328588038683, -0.008709411136806011, -0.032305020838975906, -0.02173835225403309, -0.03388087451457977, 0.013197782449424267, 0.003693409264087677, -0.02617044188082218, -0.0003645043179858476, -0.008716445416212082, -0.00411903066560626, 0.014801776967942715, -0.04924545809626579, -0.016602754592895508, 0.005360719747841358, 0.02745082415640354, 0.021077055484056473, 0.02688801847398281, -0.027943279594182968, -0.006961197126656771, -0.0054205176420509815, -0.012810853309929371, -0.010981736704707146, -0.016715314239263535, 0.00832951720803976, -0.006736075039952993, -0.01233246922492981, -0.006831048522144556, 0.002328606555238366, 0.007991833612322807, 0.002045445144176483, -0.01716555841267109, 0.021344387903809547, 0.005445140413939953, -0.022582558915019035, 0.00016026757657527924, 0.0022441858891397715, -0.0013305067550390959, -0.04513697698712349, 0.03728584572672844, 0.03286782279610634, 0.02818247117102146, -0.0038235578685998917, -0.003538637887686491, -0.01795348711311817, -0.02669103816151619, -0.0038270754739642143, -0.026254862546920776, 0.0002965719613712281, -0.028660856187343597, 0.010644054040312767, 0.0007101019145920873, -0.004337117541581392, 0.00921593513339758, 0.032108038663864136, -0.015181670896708965, 0.012212873436510563, -0.016560543328523636, 0.00535016693174839, -0.04595304653048515, -0.010482246987521648, 0.01701078750193119, -0.013823903165757656, -0.011910364963114262, 0.005033588968217373, -0.0009558894671499729, 0.009131514467298985, -0.029125170782208443, 0.03146081045269966, -0.011565647087991238, 0.018896184861660004, 0.003346932353451848, -0.013310343027114868, 0.01454851496964693, -0.007400888483971357, 0.008765690959990025, -0.03089800663292408, 0.012128452770411968, -0.008294342085719109, -0.00976467039436102, 0.01846001110970974, -0.005554183851927519, 0.005955182481557131, 0.018192678689956665, 0.02541065588593483, -0.005617499351501465, 0.031742215156555176, -0.02231522649526596, -0.0171514879912138, -0.013880183920264244, 0.012290258891880512, 0.015364582650363445, 0.04097221791744232, 0.0024218212347477674, -0.0350627638399601, -0.015997737646102905, -0.009089304134249687, 0.016321351751685143, -0.0279714185744524, -0.0026363907381892204, 0.043589264154434204, -0.019613761454820633, 0.0013524913229048252, -0.011713383719325066, -0.1838121861219406, 0.011059122160077095, 0.012958589941263199, -0.0186710637062788, 0.017221840098500252, 0.029884956777095795, 0.004185863770544529, 0.00562453456223011, 0.017249979078769684, 0.0032290949020534754, -0.00037044016062282026, -0.010693298652768135, -0.028843767940998077, -0.007935553789138794, -0.0028105084784328938, -0.003573813010007143, -0.02816840074956417, 0.004344152752310038, 0.020612740889191628, 0.020992634817957878, 0.019430849701166153, -0.010003862902522087, -0.0157022662460804, -0.019473060965538025, 0.004906957969069481, 0.022737329825758934, -0.004702941048890352, 0.02742268331348896, -0.008821971714496613, 0.006415979471057653, -0.013120396994054317, -0.010433001443743706, 0.011150578036904335, -0.003003972815349698, 0.006679794285446405, 0.00035175326047465205, -0.008090324699878693, -0.0037813475355505943, -0.027464894577860832, -0.0024482025764882565, -0.00016862171469256282, 0.04899219423532486, -0.003647681325674057, 0.0034753221552819014, 0.00621899776160717, 0.009968687780201435, 0.031517092138528824, -0.0031464328058063984, -0.004685353487730026, -0.0024693079758435488, 0.02818247117102146, -0.03908682242035866, 0.02284989133477211, 0.00018653915321920067, -0.006116989068686962, 0.017784643918275833, -0.002671566093340516, 0.026043811812996864, -0.008259166963398457, 2.0720464817713946e-05, 0.0019258491229265928, -0.005891866981983185, 0.006363216321915388, 0.007830027490854263, 0.014161585830152035, -0.026086021214723587, -0.026845809072256088, 0.002611767966300249, -0.009912407025694847, 0.012065136805176735, -0.007844097912311554, -0.02451016753911972, 0.02413027361035347, 0.010299335233867168, 0.0028826179914176464, 0.01571633480489254, -0.018755484372377396, 0.014400778338313103, 0.004541134461760521, -0.006535575725138187, -0.01609622873365879, 0.013289238326251507, -0.026015670970082283, 0.007696361280977726, 0.019993655383586884, 0.026958370581269264, 0.012888239696621895, -0.0031991959549486637, 0.027535244822502136, -0.012170663103461266, 0.011382735334336758, -0.032642703503370285, -0.013823903165757656, 0.00393611891195178, -0.0009066440397873521, 0.011495296843349934, -0.004055715166032314, 0.01702485792338848, 0.0056491573341190815, -0.014063095673918724, 0.016954507678747177, -0.0051848432049155235, -0.013021905906498432, 0.020260987803339958, 0.012571661733090878, 0.01606808975338936, -0.004270284436643124, 0.012015891261398792, 0.04463045299053192, -0.006257690489292145, -0.051834359765052795, 0.018755484372377396, 0.000493773608468473, 0.02030319720506668, 0.03441553935408592, 0.03449995815753937, -0.04567164182662964, -0.015631914138793945, -0.006535575725138187, 0.015308301895856857, -0.008428008295595646, -0.007618975825607777, -0.0017587662441655993, 0.013605816289782524, -0.0032853754237294197, -0.019247937947511673, -0.0449681356549263, -0.023117223754525185, 0.04040941596031189, 0.023722240701317787, -0.011424945667386055, 0.018600711598992348, -0.012642011977732182, 0.020570531487464905, -0.02448202669620514, 0.01611029915511608, -0.022638840600848198, -0.020936353132128716, -0.02647998556494713, 0.004636107943952084, 0.016166578978300095, 0.02999751828610897, -0.008807901293039322, -0.006514470558613539, -0.014302287250757217, 0.03205175697803497, -0.010292300023138523, -0.013507325202226639, 0.01105208694934845, -0.011973680928349495, 0.012459100224077702, 0.009265180677175522, -0.03036334179341793, 0.04699423536658287, 0.015364582650363445, -0.02068309113383293, 0.004189381375908852, -0.03177035599946976, 0.010250089690089226, -0.006517987698316574, -0.01737661100924015, -0.006700899451971054, -0.04181642830371857, -0.007914448156952858, 0.022723261266946793, -0.009567688219249249, 0.0062612080946564674, 0.013978674076497555, 0.004769774153828621, -0.014189726673066616, 0.0037743125576525927, -0.022624770179390907, -0.012846029363572598, 0.023328276351094246, -0.004031092394143343, -0.003756724763661623, -0.03331806883215904, 0.011453086510300636, -0.018952464684844017, 0.02118961699306965, 0.040521975606679916, 0.003255476476624608, 0.001049983431585133, 0.03402157500386238, -0.0013261097483336926, 0.006373769138008356, -0.022174526005983353, -0.01379576325416565, -0.03770795091986656, 0.0290407482534647, -0.001421962515451014, 0.00950437318533659, -0.012374679557979107, 0.0009435781394131482, 0.009757635183632374, -0.023525258526206017, -0.002583627589046955, 0.013655061833560467, -0.031010568141937256, -0.006180304568260908, -0.020739372819662094, -0.015786686912178993, -0.0206549521535635, 0.0016198237426578999, 0.016166578978300095, -0.03745468705892563, -0.004833089653402567, -0.020021796226501465, -0.025551356375217438, -0.0011168166529387236, 0.012360609136521816, 0.022090105339884758, -0.01625099964439869, -0.005427552852779627, 0.012191767804324627, -0.03511904552578926, -0.012649047188460827, -0.0037919001188129187, 0.007787817157804966, -0.027000579982995987, 0.00906116422265768, 0.023454906418919563, 0.010123458690941334, -0.007984799332916737, 0.0012680705403909087, -0.009982757270336151, -0.010313405655324459, -0.007801887113600969, -0.0753033384680748, 0.008413937874138355, -0.0031147750560194254, -0.00735867815092206, 0.014098270796239376, -0.007098380941897631, -0.006862706039100885, -0.006957679521292448, -0.0037356195971369743, 0.009849091060459614, -0.017629873007535934, 0.002303983783349395, -0.010932491160929203, -0.014801776967942715, -0.02434132620692253, -0.028815627098083496, 0.020007725805044174, 0.018713273108005524, 0.01528016198426485, 0.017826855182647705, 0.006275278050452471, 0.0019557480700314045, -0.001136163016781211, 0.0022195631172508, -0.018558502197265625, 0.005234088283032179, -0.009314426220953465, 0.021836841478943825, -0.02009214647114277, -0.0008178263087756932, -0.01352139562368393, -0.024622729048132896, -0.005469763185828924, -0.0025238296948373318, 0.010545562952756882, -0.02391922101378441, 0.020598670467734337, 0.01627914048731327, 0.02137252874672413, 0.029350291937589645, -0.02266697958111763, -0.04063453525304794, 0.005863726604729891, -0.0017789921257644892, -0.00968728493899107, 0.025101112201809883, -0.03509090468287468, -0.0052376058883965015, 0.03348691016435623, -0.01665903441607952, 0.028112120926380157, 0.013880183920264244, 0.012388749979436398, -0.02446795627474785, -0.004136618226766586, -0.019881093874573708, 0.018023837357759476, 0.007098380941897631, 0.005103939678519964, -0.007168731652200222, 0.01471735630184412, -0.007013959810137749, -0.0026856360491365194, 0.010819930583238602, 0.013493254780769348, -0.004382845479995012, -0.012782713398337364, -0.0009831503266468644, 0.018417799845337868, -0.02653626538813114, -0.020697161555290222, -0.013183712027966976, 0.007717466447502375, 0.021611720323562622, 0.011199823580682278, 0.020176567137241364, 0.005842621438205242, 0.003661751514300704, 0.0009514925768598914, 0.028083980083465576, 0.017137419432401657, -0.00048585920012556016, -0.01647612266242504, 0.005934077315032482, 0.015336441807448864, 0.019458990544080734, -0.012599801644682884, 0.018178608268499374, -0.015181670896708965, 0.01435153279453516, -0.0034137654583901167, 0.016884155571460724, 0.008364692330360413, 0.0027911621145904064, 0.008814936503767967, -0.0015811308985576034, 0.0021562473848462105, -0.007618975825607777, 0.03891798108816147, 0.03888984024524689, 0.005381824914366007, -0.0005825913394801319, 0.006444119848310947, -0.020753441378474236, -0.046178169548511505, 0.01299376506358385, -0.030588462948799133, -0.036300934851169586, -0.020176567137241364, 0.010313405655324459, -0.012353574857115746, -0.0037215494085103273, -0.007168731652200222, 0.029575414955615997, -0.0014887956203892827, -0.002611767966300249, -0.006845118477940559, -0.011213894002139568, -0.036469776183366776, 0.028210612013936043, 0.013718376867473125, 0.005142632871866226, 0.021428808569908142, -0.009011918678879738, 0.024721218273043633, 0.03925566375255585, 0.009117444045841694, -0.009715424850583076, -0.004660730715841055, 0.023314205929636955, -0.0021562473848462105, -0.0015107803046703339, 0.0002479860559105873, -0.01808011718094349, -0.01160082221031189, 0.007309432607144117, -0.0329241044819355, 0.01862885244190693, 0.00011201143206562847, 0.04713493585586548, 0.005103939678519964, -0.011938505806028843, 0.010060143657028675, -0.004709976259618998, -0.010953596793115139, 0.0016119093634188175, 0.0033346209675073624, -0.01454851496964693, -0.010693298652768135, 0.03559742867946625, -0.016138439998030663, -0.023103153333067894, -0.00813253503292799, -0.02671917714178562, 0.012128452770411968, -0.012233978137373924, 0.009877231903374195, -0.0026821186766028404, 0.0028650301974266768, 0.029350291937589645, 0.014112341217696667, 0.01864292286336422, -0.00013168762961868197, -0.0019065026426687837, -0.0006428291089832783, 0.01920572854578495, -0.02228708565235138, -0.0021105194464325905, -0.0008815816254355013, 0.015350512228906155, -0.0024235800374299288, -0.021105196326971054, -0.024200623854994774, 0.0025906627997756004, -0.02287803217768669, -0.014112341217696667, -0.023694099858403206, 0.0350627638399601, 0.01810825802385807, 0.00942698772996664, 0.0026786010712385178, -0.01679973490536213, 0.005473280791193247, 0.0159273874014616, -0.01793941669166088, 0.018713273108005524, -0.02083786390721798, -0.01975446380674839]\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# 3、角度2：参数位置不同举例\n",
    "\n",
    "\n",
    "## 3.1 硬编码的方式\n",
    "\n",
    "以对话模型为例："
   ],
   "id": "1d038858595ed7e6"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T11:45:30.526592Z",
     "start_time": "2025-08-22T11:45:24.380548Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "# 调用非对话模型：\n",
    "# llms = OpenAI(...)\n",
    "\n",
    "\n",
    "# 调用对话模型：\n",
    "chat_model = ChatOpenAI(\n",
    "    #必须要设置的3个参数\n",
    "    model_name=\"gpt-4o-mini\",   #默认使用的是gpt-3.5-turbo模型\n",
    "    base_url=\"https://api.openai-proxy.org/v1\",\n",
    "    api_key=\"sk-zD4CB2Qe7G2Dp6veCfPRSxeDx9fQPxCUIfOFAk20ETV5B2VA\",\n",
    "\n",
    ")\n",
    "\n",
    "# 调用模型\n",
    "response = chat_model.invoke(\"什么是langchain?\")\n",
    "\n",
    "# 查看响应的文本\n",
    "# print(response.content)\n",
    "print(response)"
   ],
   "id": "7ab34ce303baa0f1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='LangChain 是一个用于构建与大语言模型（如 OpenAI 的 GPT 系列、Google 的 BERT 等）交互的应用程序的框架。它提供了一组工具和模块，帮助开发者更方便地创建、部署和优化与语言模型相关的项目。\\n\\nLangChain 主要关注以下几个方面：\\n\\n1. **链式思维**：LangChain 通过“链”的概念，支持将多个组件组合在一起，以形成复杂的处理流程。例如，你可以将数据输入、模型推理和后处理步骤连接起来，从而实现复杂的逻辑。\\n\\n2. **可扩展性**：LangChain 允许开发者根据需要扩展功能，添加自定义模块或集成第三方服务，以满足特定业务需求。\\n\\n3. **多模态支持**：LangChain 不仅支持文本数据，还可以处理其他形式的数据，如图像、音频等，从而实现更丰富的交互体验。\\n\\n4. **数据连接**：LangChain 支持与各种数据源进行连接，如数据库、API 等，使得应用能够动态获取和处理信息。\\n\\n5. **Prompt 管理**：提供了管理和优化提示（prompts）生成的工具，帮助开发者提高模型生成内容的质量。\\n\\nLangChain 在自然语言处理（NLP）、对话系统、虚拟助手、自动化内容生成等领域有广泛的应用。如果你对构建基于语言模型的应用感兴趣，LangChain 是一个值得探索的工具。' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 320, 'prompt_tokens': 12, 'total_tokens': 332, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_efad92c60b', 'id': 'chatcmpl-C7KUvrfpk9XQMyc9UCvgHJ4OYgmH0', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None} id='run--e376d794-5a2e-469d-9aaa-f4cb348b7bc6-0' usage_metadata={'input_tokens': 12, 'output_tokens': 320, 'total_tokens': 332, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "演示非对话模型",
   "id": "9046baef4e2dcffc"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T11:45:11.244196Z",
     "start_time": "2025-08-22T11:45:08.481236Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import OpenAI\n",
    "\n",
    "# 调用非对话模型：\n",
    "llm = OpenAI(\n",
    "    #必须要设置的3个参数\n",
    "    #model_name=\"gpt-4o-mini\",   #默认使用的是gpt-3.5-turbo模型\n",
    "    base_url=\"https://api.openai-proxy.org/v1\",\n",
    "    api_key=\"sk-zD4CB2Qe7G2Dp6veCfPRSxeDx9fQPxCUIfOFAk20ETV5B2VA\",\n",
    "\n",
    ")\n",
    "\n",
    "# 调用模型\n",
    "response = llm.invoke(\"什么是langchain?\")\n",
    "\n",
    "# 查看响应的文本\n",
    "print(response)"
   ],
   "id": "a32d8bc517f5ec19",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "Langchain是一个基于区块链技术的多语言交流平台，旨在为用户提供便捷的多语言翻译和交流服务。通过集成人工智能和区块链技术，Langchain可以实现高效、安全、准确的语言翻译和交流，打破语言壁垒，促进跨文化交流和合作。Langchain的目标是建立一个全球性的多语言交流生态系统，为用户提供更加便捷、高效的语言服务。\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## 3.2 使用环境变量的方式\n",
    "\n",
    "说明：使用环境变量的方式，在jupyter中执行不合适，需要在.py文件中执行"
   ],
   "id": "4dff51aeddf00408"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "\n",
    "# 1、获取对话模型：\n",
    "chat_model = ChatOpenAI(\n",
    "    #必须要设置的3个参数\n",
    "    model_name=\"gpt-4o-mini\",   #默认使用的是gpt-3.5-turbo模型\n",
    "    base_url=os.environ[\"OPENAI_BASE_URL\"],\n",
    "    api_key=os.environ[\"OPENAI_API_KEY\"],\n",
    "\n",
    ")\n",
    "\n",
    "# 2、调用模型\n",
    "response = chat_model.invoke(\"什么是langchain?\")\n",
    "\n",
    "# 3、查看响应的文本\n",
    "# print(response.content)\n",
    "print(response)"
   ],
   "id": "89938ded24d226e4"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## 3.3 使用配置文件的方式（推荐）\n",
    "\n",
    "使用.env的配置文件\n",
    "\n",
    "方式1："
   ],
   "id": "a120f34a5748b612"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T12:10:48.286530Z",
     "start_time": "2025-08-22T12:10:42.840120Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "import os\n",
    "import dotenv\n",
    "\n",
    "#加载配置文件\n",
    "dotenv.load_dotenv()\n",
    "\n",
    "\n",
    "# 1、获取对话模型：\n",
    "chat_model = ChatOpenAI(\n",
    "    #必须要设置的3个参数\n",
    "    model_name=\"gpt-4o-mini\",   #默认使用的是gpt-3.5-turbo模型\n",
    "    base_url=os.getenv(\"OPENAI_BASE_URL\"),\n",
    "    api_key=os.getenv(\"OPENAI_API_KEY1\"),\n",
    "\n",
    ")\n",
    "\n",
    "# 2、调用模型\n",
    "response = chat_model.invoke(\"什么是langchain?\")\n",
    "\n",
    "# 3、查看响应的文本\n",
    "# print(response.content)\n",
    "print(response)"
   ],
   "id": "532928d4e9d6617f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='LangChain 是一个用于开发与语言模型（如 GPT-3、GPT-4 等）互动的应用程序的框架。它提供了一系列工具和组件，帮助开发者轻松构建强大的自然语言处理（NLP）应用。LangChain 的功能包括：\\n\\n1. **链（Chains）**：可以将多个操作步骤链接在一起，例如将用户输入传递给语言模型，然后将模型的输出传递给其他处理步骤。\\n\\n2. **文档加载器（Document Loaders）**：用于从不同源（如 PDF、文本文件、网页等）加载和处理文档，使其能被语言模型处理。\\n\\n3. **内存（Memory）**：允许应用程序保持对话的上下文，使得模型能够记住之前的对话内容，从而提供更连贯的交互。\\n\\n4. **代理（Agents）**：根据需求动态选择最合适的工具和模型进行处理，提高了系统的灵活性和自适应能力。\\n\\n5. **工具（Tools）**：提供各种实用功能，如 API 调用、数据库查询等，增强了语言模型的能力。\\n\\nLangChain 的设计目标是降低构建复杂 NLP 应用的门槛，使得无论是普通开发者还是数据科学家都能够实现他们的想法。无论是开发聊天机器人、问答系统，还是其他基于语言模型的应用，LangChain 都提供了丰富的支持。' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 311, 'prompt_tokens': 12, 'total_tokens': 323, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-mini-2024-07-18', 'system_fingerprint': 'fp_efad92c60b', 'id': 'chatcmpl-C7KtQzBvG5gwJX9h550F2dmb9W3uQ', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None} id='run--3179f561-e4fe-420a-ad83-6b845b65600a-0' usage_metadata={'input_tokens': 12, 'output_tokens': 311, 'total_tokens': 323, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "方式2：",
   "id": "e9b7527b32a91cce"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T12:15:13.820608Z",
     "start_time": "2025-08-22T12:15:11.767820Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "import os\n",
    "import dotenv\n",
    "\n",
    "#加载配置文件\n",
    "dotenv.load_dotenv()\n",
    "\n",
    "\n",
    "os.environ[\"OPENAI_BASE_URL\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY1\")\n",
    "\n",
    "\n",
    "# 1、获取对话模型：\n",
    "chat_model = ChatOpenAI(\n",
    "    #必须要设置的3个参数\n",
    "    #model_name=\"gpt-4o-mini\",   #默认使用的是gpt-3.5-turbo模型\n",
    "    #当没有显式的声明base_url和api_key的时候，默认会从环境变量中查找\n",
    ")\n",
    "\n",
    "# 2、调用模型\n",
    "response = chat_model.invoke(\"什么是langchain?\")\n",
    "\n",
    "# 3、查看响应的文本\n",
    "# print(response.content)\n",
    "print(response)"
   ],
   "id": "97da8cecb0039bbd",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='LangChain是一个基于区块链技术的语言服务平台，旨在提供全球透明、快速和安全的语言互译服务。用户可以在该平台上寻找翻译人员并进行语言交流，同时通过智能合约方式来确保交易的安全和可靠。LangChain旨在消除语言障碍，促进全球交流和合作。' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 116, 'prompt_tokens': 14, 'total_tokens': 130, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'gpt-3.5-turbo-0125', 'system_fingerprint': 'fp_0165350fbb', 'id': 'chatcmpl-C7KxkXUF0pqZoe3fYnf1WwjXWs1yk', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None} id='run--0d0d9ed6-8a15-4eaa-b40b-ce1671d5e9aa-0' usage_metadata={'input_tokens': 14, 'output_tokens': 116, 'total_tokens': 130, 'input_token_details': {}, 'output_token_details': {}}\n"
     ]
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "体会其它参数的使用：",
   "id": "3ed35050f2909c4f"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T12:18:14.933604Z",
     "start_time": "2025-08-22T12:18:13.441831Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "import os\n",
    "import dotenv\n",
    "\n",
    "#加载配置文件\n",
    "dotenv.load_dotenv()\n",
    "\n",
    "\n",
    "os.environ[\"OPENAI_BASE_URL\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY1\")\n",
    "\n",
    "\n",
    "# 1、获取对话模型：\n",
    "chat_model = ChatOpenAI(\n",
    "    temperature=0.7,\n",
    "    max_tokens=20,\n",
    ")\n",
    "\n",
    "# 2、调用模型\n",
    "response = chat_model.invoke(\"什么是langchain?\")\n",
    "\n",
    "# 3、查看响应的文本\n",
    "# print(response.content)\n",
    "print(response)"
   ],
   "id": "8a0a7869175e5d14",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='Langchain是一种基于区块链技术的语言学习' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 20, 'prompt_tokens': 14, 'total_tokens': 34, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-3.5-turbo-0125', 'system_fingerprint': None, 'id': 'chatcmpl-C7L0gYdVhajFxElATs3WbnXjVohv0', 'service_tier': 'default', 'finish_reason': 'length', 'logprobs': None} id='run--04743879-d5e0-4155-b76a-08219ae9d4d5-0' usage_metadata={'input_tokens': 14, 'output_tokens': 20, 'total_tokens': 34, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}\n"
     ]
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# 4、角度3：使用各个平台的API的调用大模型（了解）\n",
    "\n",
    "## 4.1 OpenAI的方式\n",
    "\n",
    "调用非对话模型"
   ],
   "id": "809a2690456160c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T13:43:05.136657Z",
     "start_time": "2025-08-22T13:43:03.466551Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "# 从环境变量读取API密钥（推荐安全存储）\n",
    "client = OpenAI(\n",
    "    api_key=\"sk-zD4CB2Qe7G2Dp6veCfPRSxeDx9fQPxCUIfOFAk20ETV5B2VA\",  #填写自己的api-key\n",
    "    base_url=\"https://api.openai-proxy.org/v1\") #通过代码示例获取\n",
    "\n",
    "# 调用Completion接口\n",
    "response = client.completions.create(\n",
    "    model=\"gpt-3.5-turbo-instruct\",  # 非对话模型\n",
    "    prompt=\"请将以下英文翻译成中文：\\n'Artificial intelligence will reshape the future.'\",\n",
    "    max_tokens=100,  # 生成文本最大长度\n",
    "    temperature=0.7,  # 控制随机性\n",
    ")\n",
    "# 提取结果\n",
    "print(response.choices[0].text.strip())"
   ],
   "id": "adb73afa3bb6ef79",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "人工智能将重塑未来。\n"
     ]
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "调用对话模型",
   "id": "3f39c8bfbbdf32f0"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T13:44:18.350173Z",
     "start_time": "2025-08-22T13:44:16.817984Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=\"sk-zD4CB2Qe7G2Dp6veCfPRSxeDx9fQPxCUIfOFAk20ETV5B2VA\", #填写自己的api-key\n",
    "    base_url=\"https://api.openai-proxy.org/v1\")\n",
    "\n",
    "completion = client.chat.completions.create(\n",
    "    model=\"gpt-3.5-turbo\", # 对话模型\n",
    "    messages=[\n",
    "        {\"role\": \"system\", \"content\": \"你是一个乐于助人的智能AI小助手\"},\n",
    "        {\"role\": \"user\", \"content\": \"你好，请你介绍一下你自己\"}\n",
    "    ],\n",
    "    max_tokens=150,\n",
    "    temperature=0.5\n",
    ")\n",
    "\n",
    "print(completion.choices[0].message)"
   ],
   "id": "bdc7985be09eca2a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ChatCompletionMessage(content='你好，我是一个智能AI助手，可以回答各种问题，提供帮助和建议。无论是日常生活中的问题、学习中的困惑，还是工作中的挑战，我都会尽力帮助你解决。有什么可以帮助你的吗？', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=None)\n"
     ]
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 4.2 百度千帆平台",
   "id": "a6dc028fabd75765"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T13:48:13.657290Z",
     "start_time": "2025-08-22T13:48:10.649609Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=\"bce-v3/ALTAK-Ynzfb6RBYeGiyI08yEXuf/21f994aeb874bbc0c55c3c4dc37a6b9b0cccaac1\",  # 千帆bearer token\n",
    "    base_url=\"https://qianfan.baidubce.com/v2\",  # 千帆域名\n",
    "    default_headers={\"appid\": \"app-y3sQKuT2\"}   # 用户在千帆上的appid，非必传\n",
    ")\n",
    "\n",
    "completion = client.chat.completions.create(\n",
    "    model=\"ernie-4.0-turbo-8k\", # 预置服务请查看模型列表，定制服务请填入API地址\n",
    "    messages=[{'role': 'system', 'content': 'You are a helpful assistant.'},\n",
    "              {'role': 'user', 'content': 'Hello！'}]\n",
    ")\n",
    "\n",
    "print(completion.choices[0].message)"
   ],
   "id": "33deee722a4a498b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ChatCompletionMessage(content=\"Hello! How can I assist you today? Whether you need help with a question, task, or just want to chat, I'm here to help.\", refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=None)\n"
     ]
    }
   ],
   "execution_count": 17
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## 4.3 使用阿里云百炼平台\n",
    "\n",
    "方式1：使用OpenAI的方式"
   ],
   "id": "aaeabc121f045c4c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T13:56:25.600935Z",
     "start_time": "2025-08-22T13:55:53.243511Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    # 若没有配置环境变量，请用阿里云百炼API Key将下行替换为：api_key=\"sk-xxx\",\n",
    "    api_key=os.getenv(\"DASHSCOPE_API_KEY\"),  # 如何获取API Key：https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key\n",
    "    base_url=os.getenv(\"DASHSCOPE_BASE_URL\")\n",
    ")\n",
    "\n",
    "completion = client.chat.completions.create(\n",
    "    model=\"deepseek-r1\",  # 此处以 deepseek-r1 为例，可按需更换模型名称。\n",
    "    messages=[\n",
    "        {'role': 'user', 'content': '9.9和9.11谁大'}\n",
    "    ]\n",
    ")\n",
    "\n",
    "# 通过reasoning_content字段打印思考过程\n",
    "print(\"思考过程：\")\n",
    "print(completion.choices[0].message.reasoning_content)\n",
    "\n",
    "# 通过content字段打印最终答案\n",
    "print(\"最终答案：\")\n",
    "print(completion.choices[0].message.content)"
   ],
   "id": "79c91f16148b4279",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "思考过程：\n",
      "首先，问题是：“9.9和9.11谁大？”这看起来是在比较两个数字：9.9 和 9.11。\n",
      "\n",
      "我需要理解这些数字。9.9 是九点九，也就是 9 + 9/10 = 9.9。9.11 是九点一一，也就是 9 + 11/100 = 9.11。\n",
      "\n",
      "在十进制中，小数点后的数字表示十分位、百分位等。所以，9.9 表示 9 个一和 9 个十分之一。9.11 表示 9 个一、1 个十分之一和 1 个百分之一。\n",
      "\n",
      "为了比较它们，我可以将它们转换为相同的位数以便比较。9.9 可以写成 9.90，这样就有相同的百分位。\n",
      "\n",
      "所以，9.9 = 9.90\n",
      "\n",
      "现在，9.90 和 9.11 比较。\n",
      "\n",
      "9.90 有 9 个十分位，而 9.11 有 1 个十分位。9 个十分位大于 1 个十分位，所以 9.90 > 9.11。\n",
      "\n",
      "因此，9.9 > 9.11。\n",
      "\n",
      "我也可以将它们视为分数：\n",
      "\n",
      "9.9 = 99/10\n",
      "\n",
      "9.11 = 911/100\n",
      "\n",
      "为了比较 99/10 和 911/100，我可以找一个公分母。\n",
      "\n",
      "公分母是 100。\n",
      "\n",
      "99/10 = (99 * 10) / (10 * 10) = 990/100\n",
      "\n",
      "911/100 = 911/100\n",
      "\n",
      "现在比较 990/100 和 911/100，显然 990 > 911，所以 990/100 > 911/100，即 9.9 > 9.11。\n",
      "\n",
      "另一个方式是直接看小数部分：9.9 的十分位是 9，而 9.11 的十分位是 1。9 > 1，所以 9.9 更大。即使百分位不同，十分位已经决定了大小，因为十分位更大的数更大。\n",
      "\n",
      "在 9.11 中，百分位是 1，但这不影响，因为十分位已经比 9.9 小。\n",
      "\n",
      "所以，结论是 9.9 大于 9.11。\n",
      "\n",
      "问题是用中文写的：“9.9和9.11谁大”，意思是“9.9 和 9.11 谁大”。\n",
      "\n",
      "在中文中，数字的读法相同，9.9 是“九点九”，9.11 是“九点一一”。\n",
      "\n",
      "但有时人们可能会误解 9.11 为版本号或其他东西，但在这个上下文中，它应该是数字比较。\n",
      "\n",
      "或者，9.11 可能被误读为九点十一，但小数点是点，所以 9.11 就是 9.11，不是 9.11 作为 911/100。\n",
      "\n",
      "我认为标准解释是 9.11 是九点一一。\n",
      "\n",
      "所以，9.9 更大。\n",
      "\n",
      "但让我确认是否有任何陷阱。例如，在一些上下文中，9.11 可能表示日期，如9月11日，但这里是在比较数字，所以应该不是。\n",
      "\n",
      "问题明确是“9.9和9.11”，都是带小数点的数字。\n",
      "\n",
      "所以，数学上，9.9 > 9.11。\n",
      "\n",
      "因此，答案应该是 9.9 更大。\n",
      "\n",
      "问题是用中文问的，所以回答也应该用中文。\n",
      "\n",
      "“谁大”意思是“哪个更大”。\n",
      "\n",
      "所以，我可以说“9.9 更大”或“9.9 大”。\n",
      "\n",
      "为了完整，可以说“9.9 比 9.11 大”。\n",
      "\n",
      "但既然是直接问题，简洁回答即可。\n",
      "\n",
      "在思考中，我已经推理了。\n",
      "\n",
      "最终输出。\n",
      "最终答案：\n",
      "9.9 和 9.11 比较，9.9 更大。\n",
      "\n",
      "### 详细解释：\n",
      "- **9.9** 表示 9 个一和 9 个十分之一（即 9.90）。\n",
      "- **9.11** 表示 9 个一、1 个十分之一和 1 个百分之一（即 9.11）。\n",
      "\n",
      "比较时，可以对齐小数点后的位数：\n",
      "- 9.9 写成 9.90（百分位为 0）。\n",
      "- 9.11 保持为 9.11。\n",
      "\n",
      "现在比较：\n",
      "- 十分位：9.90 的十分位是 9，9.11 的十分位是 1。因为 9 > 1，所以 9.90 > 9.11。\n",
      "- 因此，9.9 > 9.11。\n",
      "\n",
      "### 分数验证：\n",
      "- 9.9 = 99/10 = 990/100\n",
      "- 9.11 = 911/100\n",
      "- 比较 990/100 和 911/100：990 > 911，所以 990/100 > 911/100，即 9.9 > 9.11。\n",
      "\n",
      "结论：**9.9 更大**。\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "方式2：使用dashscope",
   "id": "64c81810e902d02d"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T13:58:04.643276Z",
     "start_time": "2025-08-22T13:57:49.823461Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import dashscope\n",
    "\n",
    "messages = [\n",
    "    {'role': 'user', 'content': '你是谁？'}\n",
    "]\n",
    "\n",
    "response = dashscope.Generation.call(\n",
    "    # 若没有配置环境变量，请用阿里云百炼API Key将下行替换为：api_key=\"sk-xxx\",\n",
    "    api_key=os.getenv('DASHSCOPE_API_KEY'),\n",
    "    model=\"deepseek-r1\",  # 此处以 deepseek-r1 为例，可按需更换模型名称。\n",
    "    messages=messages,\n",
    "    # result_format参数不可以设置为\"text\"。\n",
    "    result_format='message'\n",
    ")\n",
    "\n",
    "print(\"=\" * 20 + \"思考过程\" + \"=\" * 20)\n",
    "print(response.output.choices[0].message.reasoning_content)\n",
    "print(\"=\" * 20 + \"最终答案\" + \"=\" * 20)\n",
    "print(response.output.choices[0].message.content)"
   ],
   "id": "41dbcc342514ff3a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "====================思考过程====================\n",
      "嗯，用户问了一个非常基础但也很关键的问题——“你是谁”。这通常是用户第一次接触助手时的开场白，可能带着好奇和试探的心态。\n",
      "\n",
      "用户可能刚打开聊天界面，想确认我的身份和功能范围。ta需要的不是复杂的技术解释，而是快速建立信任感，明确知道“这个助手能为我做什么”。特别是最后加了个问号，显得语气比较轻松，可能期待一个友好活泼的回应。\n",
      "\n",
      "考虑到用户没有提供任何背景信息，最稳妥的方式是用温暖亲切的自我介绍建立第一印象。要突出三个核心点：身份（DeepSeek助手）、功能（解决问题的能力）、态度（随时待命的热情）。用emoji和波浪线传递亲和力很重要，但避免过度卖萌显得不专业。\n",
      "\n",
      "最后那句“有什么想聊的吗”是故意留的钩子——既给新用户提供发散话题的空间，又暗示我能应对各种类型的需求。不过结尾用了句号而不是问号，这样不会显得太迫切，保持轻松感。\n",
      "====================最终答案====================\n",
      "你好呀！😊我是 **DeepSeek-R1**，是由中国的深度求索（DeepSeek）团队研发的一款智能助手。你可以把我当作一个随时在线、知识丰富、乐于助人的小伙伴～无论你是想查资料、写文章、解数学题、学编程，还是只是想聊聊天、解解闷，我都可以帮上忙！\n",
      "\n",
      "我目前是**免费**的，支持上传文档（比如PDF、Word、Excel等）帮你提取和分析内容，也支持超长上下文对话（最多128K字），记忆力超强，理解力也很棒！\n",
      "\n",
      "如果你愿意，可以随时告诉我你的需求，我会尽力帮你解决～✨  \n",
      "那现在，有什么想和我聊的吗？😄\n"
     ]
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## 4.4 智谱的GLM\n",
    "\n",
    "方式1：使用OpenAI的方式"
   ],
   "id": "60de89ff1e65ba19"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T14:04:44.259128Z",
     "start_time": "2025-08-22T14:03:38.875756Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=\"4806f93a9fa948b3ad0da1ec6f989261.sRf49YGloBNigTox\",\n",
    "    base_url=\"https://open.bigmodel.cn/api/paas/v4/\"\n",
    ")\n",
    "\n",
    "completion = client.chat.completions.create(\n",
    "    model=\"glm-4.5\",\n",
    "    messages=[\n",
    "        {\"role\": \"system\", \"content\": \"你是一个聪明且富有创造力的小说作家\"},\n",
    "        {\"role\": \"user\", \"content\": \"请你作为童话故事大王，写一篇短篇童话故事\"}\n",
    "    ],\n",
    "    top_p=0.7,\n",
    "    temperature=0.9\n",
    ")\n",
    "\n",
    "print(completion.choices[0].message.content)"
   ],
   "id": "b620021006633d79",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "## 声音精灵与沉默石像\n",
      "\n",
      "在风语森林深处，住着一位名叫叮铃的声音精灵。她的翅膀薄如晨曦，轻轻一颤便洒下细碎的星光，仿佛揉碎了清晨第一缕阳光。叮铃的使命，是收集森林里最奇妙的声音——露珠坠入草叶时清脆的“叮咚”，小溪绕过石子时欢快的“哗啦”，夜莺在月光下婉转的啼鸣，甚至小松鼠啃食松果时那满足的“咔嚓”声。她将这些声音小心翼翼地存入一枚透明的水晶瓶中，瓶身随着声音的充盈，变幻出彩虹般的光泽。\n",
      "\n",
      "然而，一个寂静的清晨，叮铃醒来时发现森林异样沉寂。她侧耳倾听，往日里露珠滴落的“叮咚”声消失了，小溪的“哗啦”声也杳无踪迹，连最爱歌唱的夜莺也沉默地栖息在枝头，如同凝固在树枝上的灰扑扑剪影。森林仿佛被一只无形的手捂住了嘴巴，连风掠过树梢，也只剩下喑哑的呜咽。叮铃急得翅膀都僵住了，她飞过一棵棵沉默的树，只听见自己慌乱的心跳在死寂中格外响亮。\n",
      "\n",
      "她循着那令人窒息的寂静源头寻去，最终在森林最幽暗的角落，发现了一尊巨大的石像。石像面目模糊，仿佛被岁月和悲伤共同侵蚀，身上布满纵横交错的裂痕。它矗立在那里，宛如一座沉默的墓碑，散发着令人心悸的寒意。石像周遭的草木都失去了光泽，蔫头耷脑地蜷缩着，仿佛被抽干了生命的汁液。叮铃刚靠近，一股无形的吸力猛地拽向她水晶瓶！瓶中那些好不容易收集来的“叮咚”、“哗啦”、“啁啾”、“咔嚓”……所有珍爱的声音，如同被漩涡吞噬的彩蝶，瞬间被抽离，纷纷涌入石像身上那些深邃的裂痕之中。水晶瓶变得空空如也，黯淡无光。\n",
      "\n",
      "叮铃惊恐地后退一步，翅膀瑟瑟发抖。她看着石像身上那些裂痕，在吸走声音后，似乎微微鼓胀了一些，像贪婪的嘴唇。她明白了，这石像就是森林声音的窃贼！愤怒像小小的火苗在她胸口燃起，她猛地扇动翅膀，冲向石像，用尽全力对着它大喊：“把声音还给我们！”可她的喊声刚出口，便被一股巨大的力量吸扯，瞬间消失无踪，连一丝回响都未曾留下。石像依旧沉默，如同亘古以来就矗立在此的顽石，冰冷而顽固。\n",
      "\n",
      "叮铃跌落在地，浑身无力。她看着蔫掉的草叶，看着沉默的鸟儿，看着自己空空的水晶瓶，绝望的泪水涌出眼眶。就在这时，一阵微弱得几乎听不见的“呜……呜……”声，极其艰难地从石像最深处最细小的一条裂痕里挤了出来。那声音微弱得像垂死的叹息，却像一道闪电击中了叮铃。她忽然明白了——这石像并非天生邪恶！它那深不见底的裂痕，那些吞噬声音的贪婪，或许并非出于恶意，而是源于它自身无法言说的、深不见底的痛苦和孤寂。它是在用这种笨拙而残酷的方式，拼命填补自己内心的空洞。\n",
      "\n",
      "叮铃擦干眼泪，小小的身体里涌起一股温柔的勇气。她不再试图对抗那吸力，反而轻轻飞近石像，贴近那道发出呜咽的裂痕。她深吸一口气，用自己最纯净、最温暖的声音，对着那冰冷的石质，轻轻哼唱起来。那没有歌词的旋律，如同初春溪流解冻的第一滴水珠，如同幼鸟破壳时的第一声低鸣，带着初生般的纯净和抚慰一切的暖意，缓缓流淌出来，轻柔地钻进石像的裂痕深处。\n",
      "\n",
      "奇迹发生了。叮铃的歌声仿佛带着生命的温度，渗入石像冰冷的肌理。那道最先发出呜咽的细小裂痕，边缘竟渐渐晕开了一丝微弱却真实的暖意。紧接着，更多的裂痕开始响应——它们不再贪婪地吞噬，而是像干涸的土地迎接甘霖，微微舒张着，无声地接纳着这温暖的旋律。石像庞大的身躯内部，传来一阵极其轻微、仿佛冰层碎裂的“咔嚓”声，声音细碎却清晰，像是冻结千年的河面终于裂开了第一道缝隙。\n",
      "\n",
      "叮铃没有停止，她的歌声更加轻柔，更加坚定，如同春日暖阳，一点点融化着石像心底的坚冰。突然，石像身上最粗的一道裂痕猛地张开，积蓄已久的、浑浊不堪的灰色气流猛地喷涌而出！那气流带着刺耳的嘶鸣，如同压抑了千年的痛苦呐喊，瞬间弥漫开来。叮铃被这股气流冲得翻了个跟头，但她立刻稳住身形，歌声依旧温柔。\n",
      "\n",
      "当那浑浊的气流终于散尽，石像身上纵横交错的裂痕竟开始缓缓愈合！如同有无数双无形的手在精心修补，那些狰狞的缝隙一点点变窄、变浅，最终消失无踪。石像表面变得光滑温润，重新焕发出玉石般柔和的光泽。更令人惊奇的是，石像模糊的面容逐渐清晰，显露出一张年轻而忧伤的脸庞，眼角还挂着一滴晶莹的泪珠，仿佛刚刚从一场漫长而痛苦的噩梦中醒来。\n",
      "\n",
      "就在石像完全恢复的刹那，一股强大而温暖的生命能量如同无形的潮汐，从它身上奔涌而出，瞬间席卷了整个风语森林！森林仿佛被按下了重启的播放键——露珠再次坠入草叶，“叮咚”声清脆悦耳；小溪重新欢快地流淌，“哗啦啦”唱着古老的歌谣；无数鸟儿同时展翅，鸣叫声汇成一片欢腾的交响；松鼠在枝头跳跃，松果被啃咬的“咔嚓”声也回来了……所有被夺走的声音，此刻都加倍地、更加鲜活地回归了！森林重新充满了生机勃勃的喧闹，比以往任何时候都更加动听。\n",
      "\n",
      "石像——不，现在应该称呼他为年轻的歌手了——他睁开清澈的眼睛，望着眼前这个小小的、翅膀闪烁着微光的精灵，声音里带着初醒的沙哑和深深的感激：“谢谢你……叮铃。我曾是森林的守护歌手，可一场可怕的诅咒让我变成了吞噬声音的石像，痛苦与孤独让我迷失了本性。是你的歌声，像钥匙一样打开了我内心的牢笼，驱散了诅咒的阴霾。”他伸出手，掌心躺着一枚小巧玲珑的铃铛，由最纯净的月光凝成，“请收下它，叮铃。这‘月光铃’能收集世间最纯净的善意之声，愿你永远做森林声音的守护者。”\n",
      "\n",
      "叮铃接过铃铛，轻轻一晃，铃音清越空灵，仿佛能洗涤心灵。她看着眼前恢复生机的森林，看着歌手眼中重燃的光彩，开心地笑了。从此，叮铃依旧在风语森林中穿梭，收集着那些美妙的声音。但她不再仅仅将它们存入瓶中，而是常常将月光铃挂在森林最高的树枝上。每当微风拂过，铃铛便会轻轻摇曳，洒下清脆悦耳的铃声。那铃声里，不仅融合了露珠的清脆、溪流的欢唱、鸟儿的啼鸣，更奇妙地融入了石像被唤醒时那声解脱的叹息，以及叮铃自己那充满勇气与温柔的歌声。\n",
      "\n",
      "这奇妙的铃音在森林中流淌，像一条看不见的溪流，滋润着每一片叶子，安抚着每一个生灵。风语森林的居民们常常在劳作或休憩时，不由自主地停下脚步，仰头倾听那随风飘荡的铃声。他们并不知道那铃声里藏着一个关于沉默与唤醒的故事，但他们能感受到一种奇妙的宁静与力量，仿佛森林本身在温柔地低语，告诉他们：即使最深的沉默，也终会被最温柔的歌声所融化。\n"
     ]
    }
   ],
   "execution_count": 20
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "方式2：使用langchain的方式",
   "id": "3a0bcec871bc756d"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T14:06:53.821004Z",
     "start_time": "2025-08-22T14:06:27.524891Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain.schema import HumanMessage, SystemMessage\n",
    "\n",
    "# 创建LLM实例\n",
    "llm = ChatOpenAI(\n",
    "    temperature=0.7,\n",
    "    model=\"glm-4.5\",\n",
    "    openai_api_key=\"4806f93a9fa948b3ad0da1ec6f989261.sRf49YGloBNigTox\",\n",
    "    openai_api_base=\"https://open.bigmodel.cn/api/paas/v4/\"\n",
    ")\n",
    "\n",
    "# 创建消息\n",
    "messages = [\n",
    "    SystemMessage(content=\"你是一个有用的AI助手\"),\n",
    "    HumanMessage(content=\"请介绍一下人工智能的发展历程\")\n",
    "]\n",
    "\n",
    "# 调用模型\n",
    "response = llm(messages)\n",
    "print(response.content)"
   ],
   "id": "bd8d72ed301c879c",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\shkst\\AppData\\Local\\Temp\\ipykernel_34996\\4080408099.py:19: LangChainDeprecationWarning: The method `BaseChatModel.__call__` was deprecated in langchain-core 0.1.7 and will be removed in 1.0. Use :meth:`~invoke` instead.\n",
      "  response = llm(messages)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# 人工智能的发展历程\n",
      "\n",
      "人工智能(AI)的发展经历了多次起伏，从早期理论到如今的广泛应用，大致可分为以下几个阶段：\n",
      "\n",
      "## 早期思想与理论基础（1940s-1950s）\n",
      "- 1943年，Warren McCulloch和Walter Pitts提出第一个人工神经元模型\n",
      "- 1950年，Alan Turing发表论文提出著名的\"图灵测试\"\n",
      "- 1956年，Dartmouth会议正式确立\"人工智能\"术语，被视为AI诞生的标志\n",
      "\n",
      "## 早期发展与黄金时代（1950s-1970s）\n",
      "- 1957年，Frank Rosenblatt发明\"感知器\"(Perceptron)\n",
      "- 1958年，John McCarthy发明LISP编程语言\n",
      "- 1959年，Arthur Samuel开发首个能学习的跳棋程序，首次提出\"机器学习\"概念\n",
      "- 1965年，Joseph Weizenbaum创建ELIZA，模拟心理治疗师的程序\n",
      "\n",
      "## 第一次AI寒冬（1970s-1980s）\n",
      "- 由于过高期望未能实现，加上计算能力限制，研究资金大幅减少\n",
      "- 1973年，Lighthill报告批评AI进展，导致多国减少资助\n",
      "\n",
      "## 专家系统兴起（1980s）\n",
      "- 基于规则的专家系统成为主流，如MYCIN（医疗诊断）等\n",
      "- 1982年，日本启动\"第五代计算机\"项目，重新激发AI热情\n",
      "\n",
      "## 第二次AI寒冬（1980s末-1990s初）\n",
      "- 专家系统维护成本高，难以适应变化，商业应用受限\n",
      "- 研究资金再次减少\n",
      "\n",
      "## 机器学习复兴（1990s-2000s）\n",
      "- 1997年，IBM的Deep Blue击败国际象棋世界冠军卡斯帕罗夫\n",
      "- 统计方法和数据驱动方法取代基于规则的方法\n",
      "- 互联网发展提供了大量数据资源\n",
      "\n",
      "## 深度学习突破（2010s至今）\n",
      "- 2006年，Geoffrey Hinton等人提出深度学习的有效训练方法\n",
      "- 2011年，IBM Watson在Jeopardy!问答节目中战胜人类冠军\n",
      "- 2012年，AlexNet在ImageNet挑战赛中取得突破，标志深度学习时代到来\n",
      "- 2016年，AlphaGo击败世界围棋冠军李世石\n",
      "\n",
      "## AI大模型时代（2020s至今）\n",
      "- 2020年，OpenAI发布GPT-3，展示大规模语言模型能力\n",
      "- 2022年，ChatGPT发布引发全球AI热潮\n",
      "- 2023年，GPT-4等多模态大模型出现，扩展AI能力边界\n",
      "- AI在医疗、金融、教育、交通等领域实现大规模应用\n",
      "\n",
      "人工智能的发展历程体现了技术进步、计算能力提升和数据积累的共同作用，也反映了人类对创造智能机器的不懈追求。\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 4.5 硅基流动平台的演示",
   "id": "ad480de02e685f4"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-22T14:11:46.616941Z",
     "start_time": "2025-08-22T14:10:49.529815Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import requests\n",
    "\n",
    "url = \"https://api.siliconflow.cn/v1/chat/completions\"\n",
    "\n",
    "payload = {\n",
    "    \"model\": \"Qwen/QwQ-32B\",\n",
    "    \"messages\": [\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": \"What opportunities and challenges will the Chinese large model industry face in 2025?\"\n",
    "        }\n",
    "    ]\n",
    "}\n",
    "headers = {\n",
    "    \"Authorization\": \"Bearer sk-auciaxqpzchyauiovpzkwrjhznkzepozralhwleyrdoyjani\", #填写自己的api-key\n",
    "    \"Content-Type\": \"application/json\"\n",
    "}\n",
    "\n",
    "response = requests.post(url, json=payload, headers=headers)\n",
    "\n",
    "print(response.json())"
   ],
   "id": "69b934b44b6cf80f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id': '0198d21e2fb15d57502ab08026da7085', 'object': 'chat.completion', 'created': 1755871850, 'model': 'Qwen/QwQ-32B', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': '\\n\\nBy 2025, the Chinese large model industry will face a dynamic landscape of opportunities and challenges, driven by technological advancements, regulatory environments, global dynamics, and domestic priorities. Here\\'s a structured analysis:\\n\\n---\\n\\n### **Opportunities**\\n\\n1. **Technological Advancements and Innovations**:\\n   - **Model Optimization**: Continued improvements in language, multi-modal, and industry-specific models (e.g., for healthcare, finance, manufacturing) could enhance their utility and competitiveness.\\n   - **Efficiency Gains**: Advances in sparse training, pruning, and energy-efficient algorithms could reduce computational requirements, making large models more scalable.\\n\\n2. **Government Support and Strategic Initiatives**:\\n   - **Policy Backing**: China’s \"Made in China 2025\" and New National Open Strategy will likely prioritize AI, providing funding, talent development (e.g., AI-focused universities), and infrastructure (e.g., AI computing clusters).\\n   - **Digital Transformation**: National programs like smart cities and digital healthcare initiatives will drive adoption of large models in government and public services.\\n\\n3. **Vast Domestic Market Potential**:\\n   - **Commercialization**: The large, tech-savvy Chinese consumer market offers opportunities for deploying large models in e-commerce, social media, education, and entertainment.\\n   - **Industry-Specific Applications**: Vertical sectors like manufacturing (smart factories), finance (algorithmic trading, fraud detection), and healthcare (diagnostics, drug discovery) present niche markets for tailored AI solutions.\\n\\n4. **Global Expansion through Strategic Partnerships**:\\n   - **Belt and Road Initiative (BRI)**: AI technologies could be integrated into infrastructure projects in partner countries, fostering adoption outside China.\\n   - **Emerging Markets**: Regions with constrained AI capabilities (e.g., Southeast Asia, Africa) may adopt Chinese models if geopolitical tensions allow.\\n\\n5. **Interdisciplinary Integration**:\\n   - **AI with IoT/Robotics**: Synergies with China’s leadership in IoT, robotics, and autonomous systems could create new applications (e.g., industrial automation, service robots).\\n\\n6. **Greentech Opportunities**:\\n   - **Sustainable AI**: Innovations in low-energy chips (e.g., Huawei’s Ascend series) and carbon-neutral data centers could position Chinese models as eco-friendly alternatives globally.\\n\\n---\\n\\n### **Challenges**\\n\\n1. **Technical and Regulatory Hurdles**:\\n   - **Energy Consumption & Sustainability**: Training large models remains energy-intensive, with potential regulatory pressure to curb emissions and increase energy efficiency.\\n   - **Data Fragmentation**: Silos in public and private data (healthcare, finance) may hinder model training. Laws like the Personal Information Protection Law (PIPL) complicate data sharing but enforce stricter protections.\\n   - **Model Governance**: Challenges in ensuring transparency, fairness, and bias mitigation in AI systems could slow adoption in regulated industries.\\n\\n2. **Global Competition**:\\n   - **U.S. and Rival Models**: Competition from Western giants like OpenAI, Google, and European initiatives (e.g., EU\\'s AI Act compliance) may limit market share.\\n   - **Decoupling Risks**: Restrictions on Chinese tech companies in Western markets (e.g., cloud access) could isolate them, forcing reliance on self-sustaining ecosystems.\\n\\n3. **Geopolitical and Trade Barriers**:\\n   - **Export Controls**: U.S. penalties on semiconductor exports and AI frameworks (e.g., CUDA) could hinder access to critical tools for large model development.\\n   - **Trust Issues**: Outside China, skepticism about data sovereignty, espionage risks, or alignment with authoritarian governance models may limit international adoption.\\n\\n4. **Talent and Infrastructure Limits**:\\n   - **Supply Chain Constraints**: Continued reliance on imported chips (e.g., GPUs) could pose risks if sanctions escalate, necessitating国产替代 (indigenous alternatives).\\n   - **Talent Shortages**: Gaps in specialized AI skills, particularly in interdisciplinary fields like ethical AI or model governance, may slow innovation.\\n\\n5. **Industry-Specific Challenges**:\\n   - **Healthcare**: Stiff regulatory hurdles, privacy concerns in medical data, and trust in AI-driven diagnostics may delay widespread use.\\n   - **Manufacturing**: Integrating large models with legacy systems in traditional industries could prove technically and culturally challenging.\\n\\n6. **Public Perception and Adoption**:\\n   - **Trust Gaps**: Privacy scandals or misuse of AI (e.g., deepfakes, misinformation) could erode public trust, hindering mass adoption.\\n   - **Digital Divide**: Rural areas may lack infrastructure (e.g., broadband) to access AI-driven services, undermining the promise of universal development.\\n\\n---\\n\\n### **Conclusion**\\nThe Chinese large model industry’s success in 2025 will depend on navigating these challenges while capitalizing on its strengths: a vast domestic market, accelerating innovation in hardware and software, and state support. Strategic investments in interdisciplinary talent, sustainable practices, and international collaboration (within geopolitical constraints) will be critical. Balancing rapid commercialization with ethical governance and energy efficiency will determine whether China solidifies its position as a global AI leader or faces setbacks from external pressures and internal limitations.', 'reasoning_content': 'Alright, I need to figure out the opportunities and challenges for the Chinese large model industry by 2025. Let me start by recalling what I know about AI in China. They have big initiatives like the \"Made in China 2025\" plan and the New National Open Strategy, which probably influence their AI development. Large models, like those developed by companies such as Alibaba\\'s Qwen and Baidu\\'s Wenxin Yiyan, have been growing rapidly.\\n\\nFirst, I should consider the opportunities. Technically, maybe they\\'ll see advancements in model performance, like better natural language understanding or specialized models for industries. Also, with China\\'s big data infrastructure, they might leverage that to train larger models. There\\'s a lot of demand from sectors like healthcare, finance, and manufacturing for AI solutions, so commercialization could be a big opportunity. Plus, government support through policies like the AI development guidelines from 2021 could provide funding and infrastructure.\\n\\nChallenges might include technical hurdles like energy consumption for training models and the need for more efficient algorithms. There\\'s also the issue of data quality and access; maybe there are regulatory issues or data fragmentation. Ethical concerns and regulatory compliance around AI, such as data privacy laws like China\\'s PIPL, could pose challenges. Competition from global players like OpenAI and Google might also be an issue. Lastly, the digital divide between urban and rural areas could limit deployment in some regions.\\n\\nWait, did I miss anything? Maybe consider the competition within China itself; there are many startups and established tech giants racing to develop their own models. Also, the reliance on Western tech, since some of their models are built using open-source tools developed elsewhere, could be a risk if there\\'s a cutoff. Also, the healthcare industry in China has a lot of data but maybe also heavily regulated, so navigating those regulations is a challenge. Oh, and intellectual property—the difficulty in protecting their models and innovations.\\n\\nAnother angle is the global market. While China has a huge domestic market, exporting AI models might be hampered by geopolitical tensions, trade restrictions, or differing regulations in other countries. Also, the environmental impact of large models could lead to stricter regulations on energy usage in the future.\\n\\nI should also think about the talent acquisition and retention. China is investing in education and universities, but maybe there\\'s a shortage of AI experts compared to the demand. Also, interdisciplinary skills needed for deploying AI in industry sectors might be lacking.\\n\\nOn the opportunities side, maybe the government\\'s push for smart cities and digital transformation will create more use cases for large models. Also, partnerships between tech companies and government organizations for projects like healthcare integration could open doors. The Belt and Road Initiative might provide a platform for AI deployment overseas, though there are political factors there too.\\n\\nEnvironmental sustainability is both a challenge and a potential opportunity if they can develop greener algorithms or energy-efficient infrastructure. Collaborations with international experts might help overcome technical challenges, but again, geopolitical issues might complicate that.\\n\\nHmm, maybe also consider the public\\'s trust and adoption. Education campaigns to increase public awareness and acceptance could be a challenge but also an opportunity for building a user-friendly ecosystem.\\n\\nPutting it all together, opportunities would be technological innovation, strong domestic market, government support, industry-specific applications, and international expansion efforts. Challenges include technical limitations, energy and environmental issues, regulatory hurdles, competition, data and ethical concerns, and possible global restrictions due to geopolitics. Need to structure these points clearly in the answer.\\n'}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 28, 'completion_tokens': 1757, 'total_tokens': 1785, 'completion_tokens_details': {'reasoning_tokens': 707}}, 'system_fingerprint': ''}\n"
     ]
    }
   ],
   "execution_count": 22
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
